/**
 * @author Yunfeng Bai
 *
 * 2010-11-12
 */
package force;

import java.util.Collection;

import javax.vecmath.Vector3d;

import rigidbody.RigidBody;

public class GravityForce extends Force
{

    public static final Vector3d CONST_GRAVITY_FORCE = new Vector3d(0.0, -0.8, 0.0);
    
    /** Collection of rigid bodies affected by the force. */
    private Collection<RigidBody> affectedBodies;
    
    public GravityForce(Collection<RigidBody> affectedBodies_)
    {
        affectedBodies = affectedBodies_;
    }
    
    @Override
    public void apply(double t)
    {
        for(RigidBody affectedBody : affectedBodies)
        {
        	Vector3d force = new Vector3d(CONST_GRAVITY_FORCE);
        	force.scale(affectedBody.getMass());
            affectedBody.accumulateForce(force);
        }
    }
}
